<?php

/**
* Manager with filter list.
* 
*/
class Gallery_Backend_FilteredList extends Kernel_Manager_FilteredList 
{
    
    public function __construct($params = array()) 
    {
        parent::__construct($params);
        
        switch($this->_filter) 
        {
            case 'categories' : 
                $this->_default = 'edit';
                break;
            
            default :
                $this->_default = self::DEFAULT_ACTION;
                break;
        }
    }
    
    /**
     * Возвращает параметры, передаваемых в конструктор компонента, реализующего
     * указанное действие.
     *
     * @param   string  $name
     * @return  array
     */
    protected function _getActionParams($name) 
    {
        $entries = Gallery_Backend_Utils::getCategories();
        if (empty($entries) && 'add' != $name) {
            $this->_location(array('action' => 'add'));
        }
        
        $params = parent::_getActionParams($name);
        
        switch (Application::getRequest()->get('list')) 
        {
            case 'photos' : 
                $add_filter = sprintf('&%s=%d', 
                    Gallery_Backend_Utils::FILTER, 
                    Gallery_Backend_Utils::activeFilter());
                switch ($name) 
                {
                    case 'add':
                        $params['redirect_url'] .= $add_filter;
                        break;
                    case 'edit':
                        $params['redirect_url'] .= $add_filter;
                        
                        break;
                    case 'delete':
                        $params['back'] .= $add_filter;
                        break;
                }
                break;
            
            case 'categories' : 
                if ('edit' == $name) {
                    $params['id'] = Gallery_Backend_Utils::activeFilter();
                }
                break;
                
        }
        
        return $params;
    }
    
    /**
     * @desc Return manager components package.
     *
     * @return  string
     */
    protected function _package() 
    {
        return 'Gallery_Backend_' . str_camelize($this->_filter);
    }
       
}